home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / vmware-tools / vm-support < prev   
Encoding:
Text File  |  2010-12-19  |  7.9 KB  |  331 lines

  1. #!/bin/bash
  2. ##########################################################
  3. # Copyright (C) 2006-2008 VMware, Inc. All rights reserved.
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU Lesser General Public License as published
  7. # by the Free Software Foundation version 2.1 and no later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. # or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
  12. # License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public License
  15. # along with this program; if not, write to the Free Software Foundation, Inc.,
  16. # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
  17. #
  18. ##########################################################
  19.  
  20.  
  21.  
  22. #    Function: usage prints how to use this script
  23.  
  24. function usage {
  25.     echo ""
  26.     echo "Usage: $0 [-h]"
  27.     echo "    -h prints this usage statement"
  28.     exit
  29. }
  30.  
  31.  
  32. TARFILE=vm-$(date -I).$$.tgz
  33. VER=0.87
  34. OUTPUT_DIR=vm-support.$$
  35.  
  36. #    Function: banner prints any number of strings padded with 
  37. #    newlines before and after.
  38.  
  39. function banner {
  40.     echo
  41.     for option in "$@"
  42.     do
  43.         echo $option
  44.     done
  45.     echo
  46. }
  47.  
  48. #    The status constants are important and have to be kept
  49. #    in sync with VMware Workstation implementation
  50.  
  51. #    vm-support script is not running
  52. VMSUPPORT_NOT_RUNNING=0
  53. #    vm-support script is beginning
  54. VMSUPPORT_BEGINNING=1
  55. #    vm-support script running in progress
  56. VMSUPPORT_RUNNING=2
  57. #    vm-support script is ending
  58. VMSUPPORT_ENDING=3
  59. #    vm-support script failed
  60. VMSUPPORT_ERROR=10
  61. #    vm-support collection not supported
  62. VMSUPPORT_UNKNOWN=100
  63.  
  64. #    Updates the VM with the current state
  65.  
  66. function UpdateState {
  67.    if [ $update -eq 1 ]; then
  68.      vmware-xferlogs upd $1
  69.    fi
  70. }
  71.  
  72. function UpdateSpinner {
  73.         case $SPINNER in
  74.         "|")
  75.                         SPINNER="/"
  76.                 ;;
  77.  
  78.                 "/")
  79.                         SPINNER="-"
  80.                 ;;
  81.  
  82.                 "-")
  83.                         SPINNER="\\"
  84.                 ;;
  85.  
  86.                 "\\")
  87.                         SPINNER="|"
  88.                 ;;
  89.  
  90.                 *)
  91.                         SPINNER="|"
  92.                 ;;
  93.         esac
  94.         echo -en "\rPreparing Files: $SPINNER"
  95. }
  96.  
  97. #    Function: addtar copies whatever files and directories you give it to 
  98. #    a self contained output directory for later tar'ing
  99. #    Working on copies could slow this down with VERY large files but:
  100. #    1) We don't expect VERY large files
  101. #    2) Since /proc files can be copied this preserves the tree without
  102. #       having to cat them all into a file.
  103. #    3) tar barfs on open files like logs if it changes while it's tar'ing.
  104. #          Copying file first makes sure tar doesn't complain
  105.  
  106.  
  107. function addtar {
  108.     FILE=$1
  109.  
  110.     DIR=$(dirname "$FILE")
  111.     if [ ! -d "${OUTPUT_DIR}$DIR" ]; then
  112.         mkdir -p "${OUTPUT_DIR}$DIR"
  113.  
  114.         if [ $? != 0 ]; then
  115.             banner "Could not create ./${OUTPUT_DIR}$DIR... " \
  116.                 "Have you run out of disk space?" "Continuing"
  117.             return
  118.         fi
  119.     fi
  120.  
  121.     # Ignore stdout and handle errors.
  122.     UpdateSpinner
  123.     cp -pr "$FILE" "${OUTPUT_DIR}$DIR" 2>/dev/null
  124.  
  125.     # We could have failed to copy for several reasons
  126.     # If we path had a shell special character (* ? .)
  127.     # or if the file is in /proc
  128.     if [ $? != 0 ]; then
  129.         FILENAME=${FILE##*/}
  130.         for line in "$DIR"/$FILENAME
  131.         do
  132.             if [ -e "$line" ]; then
  133.                 # Ignore stdout and handle errors.
  134.                 UpdateSpinner
  135.                 cp -pr "$line" "${OUTPUT_DIR}$DIR" 2>/dev/null
  136.  
  137.                 # If a file from /proc does not copy,
  138.                 # ignore - they're funny.  
  139.                 # Otherwise, exit for failed copy.
  140.                 if [ $? != 0 ]; then
  141.                     echo "$line" | grep ^/proc > /dev/null
  142.  
  143.                     if [ $? != 0 ]; then
  144.                         banner "Could not copy $line \
  145.                             to the tar area."
  146.                         return
  147.                     fi    # Not proc
  148.                 fi # is it proc
  149.             fi # does file exist
  150.  
  151.         done # for each file in the list
  152.     fi # if copy failed
  153.  
  154. }
  155.  
  156.  
  157. #    Function: runcmd executes the command ($1) 
  158. #    redirected to a file ($2) and then adds that 
  159. #    file to the list of files to tar. 
  160. #    It then deletes the temp file since addtar makes a copy in its own
  161. #    selft contained area.
  162.  
  163. function runcmd {
  164.     $1 > $2 2>/dev/null
  165.     
  166.     if [ $? != 0 ]; then
  167.         banner "Either could not run $1 or could not write to $2" \
  168. "Do you have a full disk?" "Continuing..."
  169.     else
  170.         addtar "$2"
  171.         rm "$2"
  172.  
  173.         if [ $? != 0 ]; then
  174.             banner "Could not delete $2.  Continuing..." 
  175.         fi
  176.     fi
  177. }
  178.  
  179. update = 0
  180.  
  181. # Parse args
  182. for option in $@
  183. do
  184.         case $option in
  185.                 "-h")
  186.                         usage
  187.                 ;;
  188.                 "-u")
  189.                         update=1
  190.                 ;;
  191.                 *)
  192.                         usage
  193.                 ;;
  194.         esac
  195. done
  196.  
  197. #    Start message
  198.  
  199. UpdateState $VMSUPPORT_BEGINNING
  200.  
  201. banner "VMware Linux Support Script $VER"
  202.  
  203. #    Check for root privledge
  204.  
  205. if [ $(id -u) != "0" ]; then
  206.         banner "You are not root, some system information can't be collected."
  207. fi
  208.  
  209. # Source /etc/profile.  If we can't find it, it's the users problem to get
  210. # their paths straight.
  211.  
  212. if [ -f /etc/profile ]; then
  213.     . /etc/profile
  214. fi
  215.  
  216. # Protect against non-default values of $IFS (Not all scripts in /etc/profile.d/ 
  217. # are good citizens).
  218. unset IFS
  219.  
  220. #    make a subdir to put all your files in.  die if it does not create
  221. mkdir $OUTPUT_DIR
  222.  
  223. if [ $? != 0 ]; then
  224.     banner "Could not create ./${OUTPUT_DIR}... Exiting..." \
  225. "Please cd to a directory to which you can write" # Thanks Adam!
  226.     exit
  227. fi
  228.  
  229.  
  230. #    Add system configuration and log files. Wildcards
  231. #    may be used.
  232.  
  233.  
  234. # Try to collect bootloader config.
  235. if [ -e /etc/lilo.conf ]; then
  236.     addtar "/etc/lilo.conf"
  237. fi
  238.  
  239. # And for grub we are not sure about the exact default location so collect them
  240. # all.
  241. if [ -e /boot/grub/grub.conf ]; then
  242.     addtar "/boot/grub/grub.conf"
  243. fi
  244. if [ -e /boot/grub/menu.lst ]; then
  245.         addtar "/boot/grub/menu.lst"
  246. fi
  247. if [ -e /etc/grub.conf ]; then
  248.         addtar "/etc/grub.conf"
  249. fi
  250.  
  251. addtar "/etc/crontab"
  252. addtar "/etc/cron.daily"
  253. addtar "/etc/cron.hourly"
  254. addtar "/etc/cron.monthly"
  255. addtar "/etc/cron.weekly"
  256. addtar "/etc/modules.conf"
  257. addtar "/etc/ntp.conf"
  258. addtar "/etc/security/*"
  259.  
  260.  
  261. # Add services
  262. addtar "/etc/services"
  263.  
  264. addtar "/etc/vmware-tools/*"
  265. addtar "/var/log/boot*"
  266. addtar "/var/log/secure*"
  267. addtar "/var/log/messages*"
  268. addtar "/var/run/vmware-*"
  269.  
  270. # Add /proc with some exceptions.  stdout redirected to /dev/null.  Some files
  271. # come and go and confuse find.  Just send whatever works and don't scare user.
  272.  
  273. for procfile in `find /proc -type f 2>/dev/null| egrep -v kcore\|kmsg\|acpi\|pagemap\|/proc/$$`
  274. do
  275.     addtar "$procfile"
  276. done
  277.  
  278. #    Commands to run ($1) and redirect to logs ($2) for 
  279. #    inclusion. 
  280.  
  281. runcmd "echo vm-support version: $VER" "/tmp/vm-support-version.$$.txt"
  282. runcmd "lspci -H1 -M" "/tmp/lspci1.$$.txt"
  283. runcmd "lspci -H1 -M -vn" "/tmp/lspci2.$$.txt"
  284. runcmd "/sbin/lsmod" "/tmp/modules.$$.txt"
  285. runcmd "uname -a" "/tmp/uname.$$.txt"
  286. runcmd "df" "/tmp/df.$$.txt"
  287. runcmd "cat /etc/issue" "/tmp/issue.$$.txt"
  288. runcmd "ifconfig -a" "/tmp/ifconfig.$$.txt"
  289. runcmd "rpm -qa" "/tmp/rpm-qa.$$.txt"
  290. runcmd "netstat -lan" "/tmp/netstat-lan.$$.txt"
  291. runcmd "route" "/tmp/route.$$.txt"
  292. runcmd "mount" "/tmp/mount.$$.txt"
  293. runcmd "dmesg" "/tmp/dmesg.$$.txt"
  294. runcmd "free" "/tmp/free.$$.txt"
  295. runcmd "uptime" "/tmp/uptime.$$.txt"
  296. runcmd "date" "/tmp/date.$$.txt"
  297. runcmd "ps auwwx" "/tmp/ps-auwwx.$$.txt"
  298. runcmd "ulimit -a" "/tmp/ulimit-a.$$.txt"
  299. runcmd "umask" "/tmp/umask.$$.txt"
  300.  
  301. UpdateState $VMSUPPORT_RUNNING
  302.  
  303.  
  304. #    Perform the tar ('S' for sparse core files)
  305.  
  306. tar -czSvf $TARFILE $OUTPUT_DIR
  307.  
  308. if [ $? != 0 ]; then
  309.     banner "The tar did not successfully complete!" \
  310. "If tar reports that a file changed while reading, please attempt to rerun this script."
  311. fi
  312.  
  313. vmware-xferlogs enc $TARFILE &>/dev/null
  314.  
  315. if [ $? != 0 ]; then
  316.         banner "could not transmit logs successfully, either the xmitLogs"\
  317.         "binary is not in the path, or you are not in a virtual machine"
  318. fi
  319.  
  320. #    Clean up temporary files
  321. rm -rf $OUTPUT_DIR
  322. rm -rf $TARFILE
  323.  
  324. if [ $? != 0 ]; then
  325.     banner "$OUTPUT_DIR was not successfully removed.  Please remove manually."
  326. fi
  327.  
  328. UpdateState $VMSUPPORT_ENDING
  329.  
  330. #    End
  331.